package com.example.test.chapter16;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.example.test.R;

public class PreferencesB extends Activity {
	private TextView checkbox;
	private TextView ringtone;
	private TextView checkbox2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainpreferences_2);
		checkbox = (TextView) findViewById(R.id.checkboxpreference_b);
		ringtone = (TextView) findViewById(R.id.ringtonepreference_b);
		checkbox2 = (TextView) findViewById(R.id.checkbox2_preference);
		Button btn = (Button) findViewById(R.id.backpage);
		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				startActivity(new Intent(getApplicationContext(),
						MainChapter16.class));
				finish();
			}
		});
	}

	@SuppressLint("UseValueOf")
	@Override
	protected void onResume() {
		super.onResume();
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(this);
		checkbox.setText(new Boolean(prefs.getBoolean("checkbox", false))
				.toString());
		ringtone.setText(prefs.getString("ringtone", " "));
		checkbox2.setText(new Boolean(prefs.getBoolean("checkbox2", false))
				.toString());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_pref, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.edit_pref:
			startActivity(new Intent(this, EditPreferenceB.class));
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
